import java.io.IOException;

import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;


public class PlayerMIDI implements Runnable {
	private Player musicPlayer;

	public PlayerMIDI(String musica) throws IOException, MediaException {
		this.musicPlayer = Manager.createPlayer(
				getClass().getResourceAsStream(musica), "audio/midi");

		this.musicPlayer.realize();
		this.musicPlayer.prefetch();
	}

	public void run() {
		try {
			this.play();
		} catch (MediaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void play() throws MediaException{
		this.musicPlayer.start();
	}
	
	public long getTempoAtual(){
		return this.musicPlayer.getMediaTime();
	}
	
	public void stop() throws MediaException{
		this.musicPlayer.stop();
	}
	
	public long getTime(){
		return this.musicPlayer.getMediaTime();
	}
}
